package com.sss.productmodel.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sss.common.entities.Product;
import com.sss.common.responseutil.Result;
import com.sss.productmodel.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author sss
 * @since 2020-04-06
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService productService;


    /**
     * 商品列表
     * @return
     */
    @GetMapping("/list")
    public Result<List<Product>> productList(){
        return Result.succes(productService.list());
    }

    /**
     * 修改商品
     * @return
     */
    @PutMapping("/{id}")
    public Result<Boolean> productUpdate(@PathVariable Integer id, @RequestBody Product product, HttpServletRequest request){
        String token = request.getHeader("token");
        System.out.println("*******"+token);
        product.setId(id);
      //  int a=10/0;
        return Result.succes(productService.updateById(product));
    }


    /**
     * 查询商品详情信息
     * @return
     */
    @GetMapping("/{id}")
    public Result<Product> getProductById(@PathVariable Integer id){
        return Result.succes(productService.getById(id));
    }

}

